﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text.RegularExpressions;

/// <summary>
/// Summary description for clUtil
/// </summary>
public class clUtil
{
    public clUtil()
    {
    }

    public static string StripHTML(string str)
    {
        if (str != null)
        {
            //string output="";
            //string pattern = @"<\s*\w*\s*style.*?>";
            //Regex rgx = new Regex(pattern);
            //foreach (Match match in rgx.Matches(str))
            //    output += match.Value + " ";
            //return output;
            return System.Text.RegularExpressions.Regex.Replace(str, @"<(.|\n)*?>", string.Empty);
            //return System.Text.RegularExpressions.Regex.Match(str, @"<\s*\/?\s*span\s*.*?>",System.Text.RegularExpressions.RegexOptions.CultureInvariant).Value;

        }
        else
            return str;
    }
    public static string Substring(string stringIn, int count)
    {
        stringIn = stringIn.Trim();
        string[] arr = stringIn.Split(' ');
        string stringOut = "";
        int totalWord = arr.Length;
        if (totalWord <= count)
            stringOut = stringIn;
        else
        {
            for (int i = 0; i < count; i++)
            {
                stringOut += " " + arr[i];
            }
            stringOut += "...";
        }
        return stringOut;
    }
    public static string bodau(string input)
    {
        string[] VietnameseSigns = new string[]    {
        "aAeEoOuUiIdDyY","áàạảãâấầậẩẫăắằặẳẵ","ÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴ","éèẹẻẽêếềệểễ","ÉÈẸẺẼÊẾỀỆỂỄ", 
        "óòọỏõôốồộổỗơớờợởỡ","ÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠ","úùụủũưứừựửữ","ÚÙỤỦŨƯỨỪỰỬỮ","íìịỉĩ",
         "ÍÌỊỈĨ","đ","Đ","ýỳỵỷỹ","ÝỲỴỶỸ"};
        for (int i = 1; i < VietnameseSigns.Length; i++)
        {
            for (int j = 0; j < VietnameseSigns[i].Length; j++)
                input = input.Replace(VietnameseSigns[i][j], VietnameseSigns[0][i - 1]);
        }
        return input;
    }
    public static string genFileName()
    {
        DateTime dt = new DateTime(
            DateTime.Now.Year,
            DateTime.Now.Month,
            DateTime.Now.Day,
            DateTime.Now.Hour,
            DateTime.Now.Minute,
            DateTime.Now.Second);

        string s = String.Format("{0:yyyy MM dd HH mm ss}", dt);
        s = s.Replace(" ", "_");
        return s;
    }
    public static string showMessage(string message)
    {
        if (message != null)
        {
            message = message.Replace("\"", "'");
            message = message.Replace("\r", " ");
            message = message.Replace("\n", " ");
            return "<script language='javascript'> alert(\"" + message + "\"); </script>";
        }
        else
            return message;
    }
    //public static showMessage
}
